const sqlite3 = require('../server/node_modules/sqlite3').verbose();
const path = require('path');

// 创建数据库连接
const dbPath = path.join(__dirname, '../resources/db/db.database');
console.log('Database path:', dbPath);

const db = new sqlite3.Database(dbPath);

// 模拟progress.js中的查询逻辑
db.serialize(() => {
  console.log('\n=== Simulating Progress Route Logic ===');
  
  // 模拟获取课程进度的查询
  console.log('\n--- Course Progress Query ---');
  const userId = 1;
  const courseQuery = `
    SELECT * FROM user_course_progress 
    WHERE user_id = ? 
    ORDER BY updated_at DESC
  `;
  
  db.all(courseQuery, [userId], (err, rows) => {
    if (err) {
      console.error('Error:', err);
    } else {
      console.log('Course progress rows:', rows);
      
      // 检查是否有title字段
      if (rows.length > 0) {
        console.log('First row keys:', Object.keys(rows[0]));
      }
    }
  });
  
  // 检查user_lesson_progress表中的数据
  console.log('\n--- Lesson Progress Query ---');
  const lessonQuery = `
    SELECT * FROM user_lesson_progress 
    WHERE user_id = ? 
    ORDER BY updated_at DESC
  `;
  
  db.all(lessonQuery, [userId], (err, rows) => {
    if (err) {
      console.error('Error:', err);
    } else {
      console.log('Lesson progress rows:', rows);
      
      // 检查是否有title字段
      if (rows.length > 0) {
        console.log('First row keys:', Object.keys(rows[0]));
      }
    }
    
    db.close();
  });
});